<?php
// 连接数据库
$conn = new mysqli('localhost', 'root', '', 'your_database');

// 获取URL参数
$username = $_GET['user'];
$code = $_GET['code'];

// 验证激活码
$stmt = $conn->prepare("SELECT id FROM users WHERE username = ? AND activation_code = ? AND activated = 0");
$stmt->bind_param("ss", $username, $code);
$stmt->execute();
$stmt->store_result();

if ($stmt->num_rows > 0) {
  // 激活用户
  $stmt = $conn->prepare("UPDATE users SET activated = 1 WHERE username = ?");
  $stmt->bind_param("s", $username);
  $stmt->execute();
  echo "账户已激活！";
} else {
  echo "激活失败或链接已过期。";
}
// cron_job.php
$conn = new mysqli('localhost', 'root', '', 'your_database');
$stmt = $conn->prepare("UPDATE users SET activated = 2 WHERE activated = 0 AND created_at < NOW() - INTERVAL 1 HOUR");
$stmt->execute();
?>